#include <iostream>
#include <vector>

using namespace std;

void dfs(vector<vector<int>>& matrix, vector<bool>& visited, int i) {
    visited[i] = true;
    for (int j = 0; j < matrix.size(); j++) {
        if (matrix[i][j] && !visited[j]) {
            dfs(matrix, visited, j);
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> matrix(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> matrix[i][j];
        }
    }
    vector<bool> visited(n, false);
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            dfs(matrix, visited, i);
            count++;
        }
    }
    cout << count << endl;
	system("pause");
    return 0;
}
